package org.redmagic.service.controller;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.redmagic.service.dao.GroupDao;
import org.redmagic.service.domain.Property;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class GroupsController {

	private static final Log LOG = LogFactory.getLog(GroupsController.class);
	
	@Autowired
	private GroupDao groupDao;
	
	@RequestMapping(value="/groups", method=RequestMethod.GET)
	public HttpEntity<String> getGroups() {
		List<String> groups = groupDao.getGroups();
		return new HttpEntity<String>(groups.toString());
	}
	
	@RequestMapping(value="/groups", method=RequestMethod.GET, params="group")
	public HttpEntity<String> getGroupProperties(@RequestParam("group") String group) {
		LOG.info("Groups: " + group);
		List<Property> properties = groupDao.getProperties(group);
		
		// TODO:  change to returning back a list of properties or something more useful
		//        the string was just for testing purposes
		return new HttpEntity<String>(properties.toString());
	}
}